﻿using System;
using System.ComponentModel.Design;
using System.Globalization;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Expect.VisualStudio.Extensions.Commands;
using Expect.VisualStudio.Extensions.Commands.Handlers;

namespace Expect.VisualStudio.Extensions
{
    using System.Runtime.InteropServices;

    public class CommandSet
    {
        private IExpectPackage _package;

        public CommandSet(IExpectPackage package)
        {
            _package = package;
        }

        public void InitializeCommands(IMenuCommandService mcs)
        {
            if (mcs == null)
            {
                throw new InvalidOperationException("Menu command service should not be null");
            }

            // Create the command for the menu item.
            mcs.AddCommand(new GotoFixtureHandler(_package));
            mcs.AddCommand(new CreateContainerMethod(_package));
            mcs.AddCommand(new CreateContainerMethodWithFixtureData(_package));
            mcs.AddCommand(new CreateSpecificationMethod(_package));
            mcs.AddCommand(new CreateSpecificationMethodWithFixtureData(_package));
            mcs.AddCommand(new CreateFixtureClass(_package));
            mcs.AddCommand(new CreateActorFixtureClass(_package));
            mcs.AddCommand(new CreateActorFixtureMethod(_package));
            mcs.AddCommand(new CreateColumnFixtureClass(_package));
            mcs.AddCommand(new CreateObjectFeedFixtureClass(_package));
            mcs.AddCommand(new GenerateReportCommand(_package));
            mcs.AddCommand(new ListStylesCommand(_package));

        }

        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ShowMessage(_package, string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()));
        }

        public static void ShowMessage(IExpectPackage pkg, string msg)
        {
            // Show a Message Box to prove we were here
            IVsUIShell uiShell = (IVsUIShell)pkg.GetVSService(typeof(SVsUIShell));
            Guid clsid = Guid.Empty;
            int result;
            
            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                       0,
                       ref clsid,
                       "Expect.Extensions",
                       msg,
                       string.Empty,
                       0,
                       OLEMSGBUTTON.OLEMSGBUTTON_OK,
                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                       OLEMSGICON.OLEMSGICON_INFO,
                       0,        // false
                       out result));
        }

        public static bool Ask(IExpectPackage pkg, string msg)
        {
            // Show a Message Box to prove we were here
            IVsUIShell uiShell = (IVsUIShell)pkg.GetVSService(typeof(SVsUIShell));
            Guid clsid = Guid.Empty;
            int result;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                       0,
                       ref clsid,
                       "Expect.Extensions",
                       msg,
                       string.Empty,
                       0,
                       OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                       OLEMSGICON.OLEMSGICON_INFO,
                       0,        // false
                       out result));
            
            if (result == 6)
            {
                return true;
            }

            return false;
        }
    }
}
